<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_ACTION_PATH."base_action_class.php");
    require_once(CUTEENGINE_BASE_STEP_PATH."base_step_class.php");
	//
    // t_action_custom_code
    //
	class t_action_custom_code extends t_base_action
	{
        // property declaration
		// protected        
		// A 
		const adding_type_js_as_action_result = 1;
		const adding_type_js_content_to_a_method = 2;
		// G
		const language_position_last = 1;
		
		// property declaration
		// public
		// P
		const proper_properties_position_adding_type = 0;
		const proper_properties_position_per_code = 1;
		const proper_properties_position_per_param_1 = 2; //class_name
		const proper_properties_position_per_param_2 = 3; //method_name
		const proper_properties_position_per_param_3 = 4; //content_position
        const proper_properties_position_last = 5;
        // R
        const required_fields_count = 0;
      
        // method declaration
    	// protected
        // G
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
		static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			/*switch ($a_index) 
            {
				case self::proper_properties_position_per_:
					$local_return = '';
				break;				
			}*/
			return $local_return;
		}		
        protected function get_proper_properties_position_last()
        {
            return self::proper_properties_position_last;
        }
		protected function get_required_fields_count()
        {
            return self::required_fields_count;
        }
        

		// I
        protected function initialize_action()
        {		

			if (! $this->initialized)
			{
                parent::initialize_action();
				
				

			}
			return $this->initialized;
		}		
        protected function initialize_step_execution()
        {		
			//echo "this->current_step_index: $this->current_step_index<br>";
			if ($this->current_step_index == t_base_action::step_start)
            {
                $local_step = $this->steps_list[$this->current_step_index];
                $local_step->initialize();
                $this->custom_execute_step($local_step); 
            }                                               
		}	
        protected function custom_execute_step($a_step)        
        {
			global $g_javascript_namespace;
			if ($this->proper_properties_array[self::proper_properties_position_adding_type] == self::adding_type_js_content_to_a_method)
			{
				$local_content = $g_javascript_namespace->header_script_generator->add_content_to_a_method(
					$this->proper_properties_array[self::proper_properties_position_per_param_1],
					$this->proper_properties_array[self::proper_properties_position_per_param_2],
					$this->proper_properties_array[self::proper_properties_position_per_code]);
				
				if (($this->proper_properties_array[self::proper_properties_position_per_param_3] != -1) && ($this->proper_properties_array[self::proper_properties_position_per_param_3] !== ''))
				{	
//					echo "this->proper_properties_array[self::proper_properties_position_per_param_3]: " .$this->proper_properties_array[self::proper_properties_position_per_param_3]; 	
					$g_javascript_namespace->header_script_generator->move_method_content(
						$this->proper_properties_array[self::proper_properties_position_per_param_1],
						$this->proper_properties_array[self::proper_properties_position_per_param_2],
						$local_content, 
						$this->proper_properties_array[self::proper_properties_position_per_param_3]);	
				}		
			}		
        }
        // method declaration
    	// public
        public function __construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str) 
		{
            parent::__construct($a_parent_component,$a_parent_part,$a_common_properties_str, $a_proper_properties_str);
          //  echo "count:".count($this->fields_list);
			// steps
           
			$this->steps_list[t_base_action::step_start] = t_base_step::create_step_from_string('|t_step_ajax_put|'.$this->get_action_name().'_res|'.
              $this->fields_list[t_base_action::step_start].'|');  
		}
        // D
		public function do_action_from_ajax($a_result)
        {
			//echo "this->proper_properties_array[self::proper_properties_position_per_code]: ".$this->proper_properties_array[self::proper_properties_position_per_code]."<br>";
			if ($this->proper_properties_array[self::proper_properties_position_adding_type] == self::adding_type_js_as_action_result)
			{
				$a_result->add_function_result("","","", 
					$this->proper_properties_array[self::proper_properties_position_per_code]); 	
			}		
		}
		
		// S
		public function set_code($a_code)
        {
			$this->proper_properties_array[self::proper_properties_position_per_code] = $a_code; 	
					
		}
        
    }
?>    